package com.bw.dubbo;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.bw.service.UserService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by qpx on 2018/6/21.
 */
@Configuration
public class DubboConfig {


    @Bean
    public UserService userService(){
        ApplicationConfig config = new ApplicationConfig();
        config.setName("consumer1");


        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setAddress("zookeeper://localhost:2181");


        ReferenceConfig<UserService> userServiceReferenceConfig = new ReferenceConfig<>();
        userServiceReferenceConfig.setInterface(UserService.class);
        userServiceReferenceConfig.setRegistry(registryConfig);
        userServiceReferenceConfig.setApplication(config);
        UserService userService = userServiceReferenceConfig.get();
        return userService;

    }


}
